home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / DDPLUS71.ZIP / OVERLAY.ZIP / OVERLAY.DOC < prev   
Encoding:
Text File  |  1995-03-18  |  8.4 KB  |  190 lines

  1.                            AUTOMATIC OVERLAY UNIT
  2.                               Copyright 1995
  3.                                    By
  4.                      Neil J. Rubenking and Bob Dalton
  5.  
  6.                                INTRODUCTION:
  7.                                ------------
  8.           At one time or another your door program will get so large
  9.           that you will need to overlay a portion of it to conserve
  10.           memory. This unit adds that function to the DDPlus package.
  11.           The INITOVER.PAS code included in this archive is FREEWARE
  12.           and can be used in any manner you want and without cost, but
  13.           remains copyrighted to Neil Rubenking. Everything else
  14.           is copyrighted by Bob Dalton. I have made several changes to
  15.           that unit to allow them to function better with doors, so
  16.           blame any errors from changes on Bob Dalton. I am not an
  17.           expert on overlay techniques so feel free to contribute
  18.           enhancements, corrections, etc if you see something which
  19.           could be done better, faster, etc..
  20.  
  21.                                 REQUIREMENTS:
  22.                                 ------------
  23.           At this point in time the only requirements are that you must
  24.           be using Borland Turbo Pascal version 6.0 or 7.0.  I compiled
  25.           the unit with Borland Pascal 7.0 Professional and know it
  26.           works. I expect it will with TP 6.0 as well but can't guarantee
  27.           it. 
  28.  
  29.                                 Files Included
  30.                                 --------------
  31.           Below is a listing of all files for the OVERLAY.ZIP Package:
  32.  
  33.           OVERLAY.DOC  - The text file you are reading.
  34.           INITOVER.PAS - The Overlay routines unit by Neil Rubenking.
  35.  
  36.                     Installation and Preparation for Use
  37.                     ------------------------------------
  38.  
  39.           1. Move the archive package to a temporary directory and "unzip".
  40.  
  41.           2. Before compiling the INITOVER.pas unit be sure that your
  42.              compiler knows where to find the listed units.
  43.  
  44.           3. Add INITOVER to the "Uses" portion of your program and call
  45.              the procedures as needed and shown below.
  46.  
  47.           4. That's it!  Enjoy and good luck.
  48.  
  49.  
  50.                    ABOUT OVERLAYS AND HOW TO USE THEM
  51.                    ----------------------------------
  52.           
  53.           1.  If an EMS driver can be detected and if enough EMS memory
  54.           is available, the OvrInitEMS loads all overlays into EMS and
  55.           close the overlay file. Subsequent overlay loads are reduced
  56.           to fast in memory transfers. OvrInit installs an exit procedure,
  57.           which automatically deallocates EMS memory upon termination of
  58.           your door program. In case any error occurs, such as NO EMS
  59.           driver present, then overlays will be read from disk.
  60.          
  61.           2.  Using OvrInitEMS to place the file in EMS doesn't eliminate
  62.           the need for an overlay buffer.  Overlays must still be copied
  63.           from EMS into normal memory in the overlay buffer before they
  64.           can be executed, but because such-in memory transfers are
  65.           significantly faster than disk reads, there is less need to
  66.           increase the size of the overlay buffer.
  67.           
  68.           3.  When it is executing overlaid units, Turbo Pascal allocates 
  69.           as much space in the code segment as needed by the largest of
  70.           the overlaid units, so try to keep your units more or less the
  71.           same size.
  72.  
  73.           4.  As stated above remember that if there is not enough EMS
  74.           allocated or available then it loads the unit into overlay
  75.           buffer memory from disk instead of EMS. Doing it from disk
  76.           takes time and this is the tradeoff you make to reduce code
  77.           size. Using overlays wisely, however, can minimize the cost
  78.           in speed. First, overlaying seldom used units minimizes the
  79.           impact on the overall execution speed of the program; you will
  80.           barely notice the time required to load such units.  If
  81.           however, the overlay needs to be loaded every few minutes or
  82.           seconds, the impact will be much greater. Keep in mind that
  83.           only ONE overlaid unit can be in buffer memory at any one time
  84.           using THIS unit.  In other words ProcedureB (overlaid) cannot
  85.           call to ProcedureA which is also in another overlaid unit. If
  86.           it does, Turbo Pascal will load Unit A which contains ProcedureA,
  87.           thus wiping out Unit B which contains ProcedureB in the process,
  88.           which will slow things down and possibly cause a crash or a hang.
  89.           Be very careful to ensure that your door program contains no
  90.           conflicting overlay calls of this nature. Ideally the units
  91.           which are overlaid should make NO procedure/function calls to
  92.           any other OVERLAID unit, but only to non-overlaid units.  In
  93.           future versions of DDPlus we will expand this package and show
  94.           you how to get around that limitation and use some more
  95.           sophisticated overlay techniques.
  96.  
  97.           5.   You cannot overlay ANY unit that makes a dos interrupt
  98.           service call, or interrupt handlers such as SYSTEM, OVERLAY,
  99.           GRAPH, TURBO3, GRAPH3, CRT, ELOG.PAS or INITOVER.PAS unit. See
  100.           your Borland reference books for further information, if you
  101.           need to know more (in the Language Guide pg 250 for Borland
  102.           Pascal with Objects TP 7.0).
  103.  
  104.           6.   See the INITOVER.PAS unit for other things you will have
  105.           to do.
  106.  
  107.           7.   To avoid overlay "thrashing" do not overlay units you
  108.           use a lot.
  109.  
  110.                         TO USE THE INITOVER.PAS UNIT
  111.                         ---------------------------
  112.  
  113.  If your program becomes to large you can use this unit to provide automatic
  114.  overlay initialization and setup. To use it see the partial extract of the
  115.  following door example (main unit) for GodFather of Crime (GOC):
  116.  
  117.  PROGRAM World;
  118.            {$B+}
  119.            {$R-}
  120.            {$S+}
  121.            {$I+}
  122.            {$N-}
  123.            {$M 65520,16384,655360}
  124.  
  125.            Uses Overlay,    {Must be listed first!}
  126.                 InitOver,   {Must be listed second!}
  127.                 Dos,        {Must be listed third, if used}
  128.                 Crt,        {Must be listed fourth, if used}
  129.                 DDPlus,     {Must be listed next}
  130.                 Wutil,      {your other units you are using are listed next}
  131.                 WorldVar,
  132.                 Wmap,
  133.                 WStart,
  134.                 Woption,
  135.                 Wsave,
  136.                 Woption2,
  137.                 Woption3,
  138.                 Wduel;
  139.  
  140.          {$O DDOvr }     {Must be shown if you are using overlays}
  141.          {$O DDOvr2 }    {Must be shown if you are using overlays}
  142.          {$O Wmap }      {Next comes the units you intend to overlay}
  143.          {$O Woption }
  144.          {$O Woption2 }
  145.          {$O Woption3 }
  146.          {$O Wduel }
  147.  
  148.          Var Dummy:PlayerRecord;
  149.  
  150.          etc...
  151.  
  152.  In each of the overlayed units you would show the following:
  153.  
  154.  
  155.          UNIT Wmap;
  156.          {$F+,O+,V-}                             {Must be exactly as shown}
  157.          INTERFACE
  158.          Uses Crt,WorldVar,DDPlus,Wutil;         {units used by this unit}
  159.  
  160.          Procedure InitGraph(VAR M: MapArray);   {your various procedures}
  161.          Procedure ShowGraph( M: MapArray );
  162.          Procedure InitCountry( VAR C: CountryArray );
  163.  
  164.          etc...
  165.  
  166.  Here is a sample of the first several lines of my main program which shows
  167.  you how to implement some of the above:
  168.  
  169.  BEGIN (***  M A I N  ***)
  170.   OvrFileMode := 64;                 {File mode for overlay units}
  171.   GetDate(Year,Month,Day,DOW);
  172.   INITDOORDRIVER('GOC.CTL');
  173.   PROGNAME:='GODFATHER OF CRIME by Bob Dalton';
  174.   NOTIME:='*** TIME HAS EXPIRED ***';
  175.   If Graphics < 3 Then
  176.   Begin
  177.     Wn('The game requires ANSI or RIP color and graphics.');
  178.     Wn('Your current parameters do not qualify you for either.');
  179.     Wn('To play this game, go back to the BBS and select the ANSI');
  180.     Wn('or RIP graphics option usually found in the Utilities Menus.');
  181.     Crlf;Wn('ASK YOUR SYSOP IF YOU HAVE FURTHER PROBLEMS!');
  182.     Crlf;
  183.     Crlf;
  184.     Wn('Sending you back to the BBS.....');
  185.     Delay(2500);
  186.     Crlf;
  187.     Exit
  188.    End;
  189.  
  190.